package com.sbpm.crmbpm.client.deprecforms;

import com.sbpm.crmbpm.shared.data.TransferInfo;
import com.sencha.gxt.core.client.util.ToggleGroup;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.form.*;

import java.util.HashMap;
import java.util.Map;


/**
 * @deprecated
 */
public abstract class VerifyTransferForm extends ProcessForm
{

    private TextField name;
    private TextField sum;
    private TextField receiver;
    private CheckBox isApproved;
    private ToggleGroup group;
    private Radio approved;
    private Radio notApproved;
    private TransferInfo transfer;
    private Long id;
    private Long processInstanceId;

    public VerifyTransferForm()
    {
        init( "Verify transfer" );
    }

    @Override
    public Map< String, Object > getData()
    {
        Map< String, Object > map = new HashMap<>();
        //MessageBox box = new MessageBox( "!" + approved.getValue() + "!" );
        //box.show();

        map.put( "approved", isApproved.getValue().toString() );
        return map;
    }

    @Override
    public void setData( Map< String, Object > data )
    {
        /*name.setValue( ( String )data.get( "Name" ) );
        sum.setValue( ( String )data.get( "Sum" ) );
        receiver.setValue( ( String )data.get( "Receiver" ) );*/
//        transfer = ( TransferInfo ) data.get( "transfer" );
//        name.setValue( transfer.getName() );
//        sum.setValue( transfer.getSum() );
//        receiver.setValue( transfer.getReceiver() );
        name.setValue( ( String )data.get( "transfer.name" ) );
        sum.setValue( ( String )data.get( "transfer.sum" ) );
        receiver.setValue( ( String )data.get( "transfer.receiver" ) );
        id = ( Long )data.get( "transfer.id" );
        processInstanceId = ( Long )data.get( "transfer.processInstanceId" );

    }

    public void createForm( FramedPanel panel )
    {
        FieldSet fieldSet = new FieldSet();
        fieldSet.setHeadingText( "Transfer information" );
        fieldSet.setCollapsible( false );
        panel.add( fieldSet );

        VerticalLayoutContainer p = new VerticalLayoutContainer();
        fieldSet.add( p );

        name = new TextField();
        name.setReadOnly( true );
        name.setAllowBlank( false );
        p.add( new FieldLabel( name, "Name" ), new VerticalLayoutData( 1, -1 ) );

        sum = new TextField();
        sum.setReadOnly( true );
        sum.setAllowBlank( false );
        p.add( new FieldLabel( sum, "Sum" ), new VerticalLayoutData( 1, -1 ) );

        receiver = new TextField();
        receiver.setReadOnly( true );
        receiver.setAllowBlank( false );
        p.add( new FieldLabel( receiver, "Receiver" ), new VerticalLayoutData( 1, -1 ) );

        isApproved = new CheckBox(  );
        isApproved.setBoxLabel( "Approve?" );
        p.add( isApproved, new VerticalLayoutData( 1, -1  ) );

        /*approved = new Radio();
        approved.setBoxLabel( "Approved" );

        notApproved = new Radio();
        notApproved.setBoxLabel( "Not Approved" );

        HorizontalPanel hp = new HorizontalPanel();
        hp.add( approved );
        hp.add( notApproved );

        group = new ToggleGroup();
        group.add( approved );
        group.add( notApproved );

        p.add( hp, new VerticalLayoutData( 1, -1 ) );*/


    }


}
